package com.zhb.lkd.controller;

import com.zhb.lkd.base.ResponseResult;
import com.zhb.lkd.pojos.vo.taskReportInfoVo;
import com.zhb.lkd.service.INodeService;
import com.zhb.lkd.service.IOrderService;
import com.zhb.lkd.service.IPartnerService;
import com.zhb.lkd.service.ITaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author shadow
 */
@RestController
@RequestMapping("/api")
@Slf4j
@Api(tags = "首页统计相关接口")
public class IndexController {
    @Resource
    private IOrderService orderService;
    @Resource
    private INodeService nodeService;
    @Resource
    private IPartnerService partnerService;
    @Resource
    private ITaskService taskService;

    @GetMapping("/order-service/report/orderCount")
    @ApiOperation("订单统计")
    public ResponseResult orderCount(
            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime start,
            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime end) {
        log.info("订单统计" + start + "-" + end);
        // 查询订单数量
        Long count = orderService.orderCount(start, end);
        return ResponseResult.ok(count);
    }


    @GetMapping("/order-service/report/orderAmount")
    @ApiOperation("销售额统计")
    public ResponseResult orderAmount(
            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime start,
            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime end) {
        log.info("销售额统计" + start + "-" + end);
        // 查询订单数量
        Long salesVolume = orderService.orderAmount(start, end);
        return ResponseResult.ok(salesVolume);
    }


    @GetMapping("/vm-service/node/count")
    @ApiOperation("点位数量")
    public ResponseResult orderAmount() {
        log.info("点位数量");
        Integer count = nodeService.nodeCount();
        return ResponseResult.ok(count);
    }

    @GetMapping("/user-service/partner/count")
    @ApiOperation("合作商数量")
    public ResponseResult partnerCount() {
        log.info("合作商数量");
        Long count = partnerService.partnerCount();
        return ResponseResult.ok(count);
    }

    @GetMapping("/task-service/task/taskReportInfo/{start}/{end}")
    @ApiOperation("工单统计")
    public ResponseResult taskReportInfo(
            @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime start,
            @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime end) {
        log.info("工单统计" + start + "-" + end);;
        List<taskReportInfoVo> taskReportInfo = taskService.taskReportInfo(start,end);
        return ResponseResult.ok(taskReportInfo);
    }
}
